﻿//Write a program that finds the maximal increasing sequence in an array. Example: {3, 2, 3, 4, 2, 2, 4}  {2, 3, 4}.


using System;

namespace MaximalIncreasingSequence
{
    class MaximalIncreasingSequence
    {
        static void Main()
        {
            int[] testArray = { 1, 5, 2, 0, 2, 3, 4 }; //itiliazing testArray
            int tempLenght = 1;
            int bestLenght = 0;
            int endIndex = 0;

            for (int i = 1; i <= testArray.Length; i++)
            {
                if (i < testArray.Length)
                {
                    if (testArray[i - 1] < testArray[i])    //checking for increasing numbers in the arr
                    {
                        tempLenght++;
                    }
                    else
                    {
                        if (tempLenght > bestLenght)
                        {
                            bestLenght = tempLenght;
                            endIndex = i;
                        }
                        tempLenght = 1;
                    }
                }
                else
                {
                    break;
                }
            }

            if (tempLenght > bestLenght)    //Last check for end of the array
            {
                bestLenght = tempLenght;
                endIndex = testArray.Length;
            }

            Console.Write("\n{ ");
            for (int i = endIndex - bestLenght; i < endIndex; i++)
            {
                Console.Write(testArray[i] + ((i < endIndex - 1) ? ", " : ""));
            }
            Console.Write(" }\n\r");

        }
    }
}
